home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Navigation Services SDK / Examples / StExample / StNavServices.h < prev   
Encoding:
Text File  |  1999-06-16  |  4.9 KB  |  152 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        StNavServices.h
  3.  
  4.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. //    Stack Based classes for Navigation Services calls - NavGetFile, NavPutFile
  9.  
  10. //    
  11. //    You may incorporate this sample code into your applications
  12. //    without restriction. This sample code has been provided "AS
  13. //    IS" and the responsibility for its operation is 100% yours.
  14. //    You are not permitted to redistribute the source as "Apple
  15. //    sample code" after having made changes. If you're going to
  16. //    re-distribute the source, we require that you make it clear
  17. //    in the source that the code was descended from Apple sample
  18. //    code, but that you've made changes.
  19. //    
  20.  
  21. #ifndef __NAVIGATION__
  22. #include <Navigation.h>
  23. #endif
  24.  
  25. #ifndef _H_UMemoryMgr
  26. #include <UMemoryMgr.h>
  27. #endif
  28.  
  29. #include <Types.h>
  30. #include <Files.h>
  31. #include <stdarg.h>
  32.  
  33.  
  34. //    provides automatic disposal of NavReplyRecord 
  35. class StNavReplyDeleter
  36. {
  37. public:
  38.     StDeleter<NavReplyRecord> data;
  39.     ~StNavReplyDeleter ( ) { if ( data.IsOwner() ) NavDisposeReply ( data.Get() ); }
  40. };
  41.  
  42.  
  43. //    a convenient callback for opening files
  44. typedef pascal OSErr (*StNavGetFile_OpenEventHandler) ( FSSpecPtr openSpec );
  45.  
  46. enum {
  47.     StNavGetFileOpenProcInfo = kPascalStackBased 
  48.         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  49.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpecPtr)))
  50. };
  51.  
  52. #if GENERATINGCFM
  53. typedef UniversalProcPtr StNavGetFileOpenEventUPP;
  54. #else
  55. typedef StNavGetFile_OpenEventHandler StNavGetFileOpenEventUPP;
  56. #endif
  57.  
  58. #if GENERATINGCFM
  59. #define NewStNavGetFileOpenProc(userRoutine)        \
  60.         (StNavGetFileOpenEventUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), StNavGetFileOpenProcInfo, GetCurrentArchitecture())
  61. #else
  62. #define NewStNavGetFileOpenProc(userRoutine)        \
  63.         ((StNavGetFileOpenEventUPP) (userRoutine))
  64. #endif
  65.  
  66. class StNavGetFile
  67. {
  68. public:
  69.     //    open file(s) with most NavGetFile options available
  70.     //        result - of the call
  71.     //        specs - ptr to user's FSSpecArrayPtr
  72.     //                if given:
  73.     //                    if (getOneFile) then gets written with pointer to FSSpecArray of opened file(s)
  74.     //                    else gets single FSSpec data written to the address (in specs)
  75.     //        numspecs - ptr to number of files opened
  76.     //        openProc - gets called for each file opened
  77.     //        reply - user's NavReplyRecord
  78.     //                user must call NavDisposeReply after using data in reply
  79.     //    *** ONE of the above (openPrec, specs, reply) MUST be supplied
  80.     //        getOneFile - set to true (default) if only one file wanted
  81.     //        showAllReadableFiles - set to true (default) if all readable files should be shown
  82.     //        eventProc, eventProcUD, previewProc, filterProc (see Programming with Navigation Services documentation)
  83.     //        typeList - user's list of files that can be opened
  84.     //                    if nil, attempts to use default (open resource, see I.M. Translation Mgr.)
  85.     StNavGetFile ( OSErr                 *result,
  86.                     void                *specs = nil,
  87.                     long                *numspecs = nil,
  88.                     StNavGetFileOpenEventUPP openProc = nil,
  89.                     NavReplyRecord        *reply = nil,
  90.                     Boolean                getOneFile = true,
  91.                     Boolean                showAllReadableFiles = true,
  92.                     NavEventUPP         eventProc = nil,
  93.                     NavPreviewUPP         previewProc = nil,
  94.                     NavObjectFilterUPP    filterProc = nil,
  95.                     NavTypeListHandle    typeList = nil,
  96.                     NavCallBackUserData    eventProcUD = 0L );
  97.         
  98.     virtual ~StNavGetFile ( );
  99.     
  100.     //    create a NavTypeListHandle from a variable list of file types
  101.     //        if applSignature is 0L, use current process info signature
  102.     static NavTypeListHandle MakeTypeList ( OSType applSignature, int numTypes, ... );
  103.  
  104.     //    create a NavTypeListHandle from a static list of file types
  105.     //        if applSignature is 0L, use current process info signature
  106.     static NavTypeListHandle MakeTypeList ( OSType applSignature, int numTypes, OSType *types );
  107.     
  108.     static void GetFSSpecFromAEDesc ( AEDesc &inDesc, FSSpec &outValue );
  109.     
  110.     friend class StNavPutFile;
  111. protected:
  112.     static OSErr         Init ( );
  113.     static OSType         GetApplSignature ( );
  114.  
  115.     NavDialogOptions    fdialogOptions;
  116.     FSSpecArrayPtr        fTheirSpecs;
  117.     StNavReplyDeleter    fReply;
  118.     NavEventUPP            fTheirEventUPP;
  119.     NavCallBackUserData    fTheirEventUD;
  120. };
  121.  
  122. class StNavPutFile
  123. {
  124. public:
  125.     //    save a file
  126.     //    result - of the call
  127.     //    fileType - of the file
  128.     //    fileCreator - of the file
  129.     //                    fileType & fileCreator are used to formulate translation options
  130.     //                    (see Programming with Navigation Services, NavPutFile)
  131.     //    spec - optional pointer to FSSpec of file
  132.     //    reply - user's NavReplyRecord (destructor will dispose of it)
  133.     //    eventProc, eventProcUD to handle events during dialog (see Programming with Navigation Services)
  134.     StNavPutFile ( OSErr                *result,
  135.                     OSType                 fileType,
  136.                     OSType                 fileCreator,
  137.                     FSSpecPtr            spec = nil,
  138.                     NavReplyRecord        *reply = nil,
  139.                     NavEventUPP         eventProc = nil,
  140.                     NavCallBackUserData eventProcUD = 0L );
  141.  
  142.     //    takes care of finishing the save process (calls NavCompleSave, NavDisposeReply)
  143.     virtual ~StNavPutFile ( );
  144.                     
  145. protected:
  146.     OSErr                *fresult;
  147.     NavDialogOptions    fdialogOptions;
  148.     StNavReplyDeleter    fReply;
  149.     NavEventUPP            fTheirEventUPP;
  150.     NavCallBackUserData    fTheirEventUD;
  151. };
  152.